Skip to content

Preserve relative source symlink targets - #980

Open
gibkim wants to merge 3 commits into
aws:developfrom
gibkim:fix/relative-source-symlink-targets
Open

gibkim wants to merge 3 commits into
aws:developfrom
gibkim:fix/relative-source-symlink-targets

Conversation

@gibkim

@gibkim gibkim commented Nov 21, 2026 •

Copy link
Copy Markdown

Issue #, if available: N/A

Description of changes

With maintain_symlinks=True, copytree and CopyDependenciesAction interpreted relative readlink() targets against the working directory, which could select a different file or directory.

Use a shared internal helper to anchor targets to the source link. On Windows, expand directory symlinks crossed by leading parent components while retaining junction context and final target links. Reject targets that escape the volume root instead of selecting a valid file after normalization. Existing absolute targets, default copying and copy fallback are preserved.

Description of how you validated changes

  • macOS: env -u RUST_LOG make pr passed 1,213 tests and 64 subtests, with 9 Windows-only skips and 94.94% coverage; Ruff and Black passed. The inherited Rust logging override also fails its logger test on the base.
  • Native Windows diagnostics checked out this exact commit and passed make pr on Python 3.10 and 3.14. All 25 new regressions and 17 additional source-target cases passed on both versions. These fork diagnostics are separate from upstream approval gates.
  • Fresh fixed-commit independent review reran related tests, macOS adversarial cases and ntpath model checks; no actionable findings.

AI-assisted implementation and CI fixes with Codex/GPT-6.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Resolve relative readlink targets from the original link parent in both
copytree and dependency copying, rather than the current directory.

Assisted-by: Codex/GPT-6
@gibkim
gibkim requested a review from a team as a code owner November 21, 2026 10:18
@github-actions github-actions Bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Nov 21, 2026

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Lambda Tooling PR Reviewer: No high-confidence issues found.

1 lower-confidence observation: these passed verification at a lower score, so check before acting

1. [BUG] aws_lambda_builders/utils.py:108: Joined relative target may resolve to the wrong path on Windows when the link's parent is a directory symlink

The new code joins the raw os.readlink() target onto the unresolved parent, which gives a path like root\alias\..\target. create_symlink_or_copy passes that path through Path.absolute(), which does not normalize it. Win32 path handling removes .. as text before it follows the alias reparse point, so the new link (or the copy fallback) would point at root\target instead of root\real\target. The same line appears at aws_lambda_builders/actions.py:239. To check, run the new source_alias=True test cases on native Windows CI. If they read "wrong target", resolving the parent first with os.path.join(os.path.realpath(os.path.dirname(new_source)), os.readlink(new_source)) should fix both call sites.

Expand source-parent directory symlinks crossed by relative parent
components while retaining junction context and final target links.
Reject invalid targets that escape their volume root.

Assisted-by: Codex/GPT-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants